package com.gzasc.good.service.impl;

import com.gzasc.good.entity.Goods;
import com.gzasc.good.service.GoodsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GoodsServiceImpl implements GoodsService {
    //初始化商品列表
    private static final Map<Integer, Goods> goodsMap = new HashMap<>();
    static {
        Goods goods1 = new Goods(1,"手机", 5000);
        Goods goods2 = new Goods(2,"平板", 3000);
        Goods goods3 = new Goods(3,"洗衣机", 2000);
        goodsMap.put(goods1.getId(), goods1);
        goodsMap.put(goods2.getId(), goods2);
        goodsMap.put(goods3.getId(), goods3);
    }
    @Override
    public List<Goods> findAll(){
        return new ArrayList<>(goodsMap.values());
    }
    @Override
    public Goods findById(Integer id){
        return goodsMap.get(id);
    }
}
